home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: thinkage.on.ca!atbowler
- From: atbowler@thinkage.on.ca (Alan Bowler)
- Subject: Re: Trouble with file return code.
- Message-ID: <DLAv0C.GqF@thinkage.on.ca>
- Sender: news@thinkage.on.ca
- Organization: Thinkage Ltd.
- References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca> <4d3h96$9fl@news.iag.net>
- Date: Wed, 17 Jan 1996 00:36:12 GMT
-
- In article <4d3h96$9fl@news.iag.net> jatmon@iag.net (John R Buchan) writes:
- >
- > /* Of course, you'll want to do better i/o testing, but basically */
- > while( fread(buf, sizeof(buf), 1, ptr) == 1)
-
- I know you covered yourself with a disclaimer, but this one is very
- dicy. If fread get an EOF part way though the "sizeof buf" bytes
- it may return 0 or 1. (does the library round up or down?).
- I suggest
-
- while(sizeof buf == (count = fread(buf, 1, sizeof(buf), ptr))) {
- /* play with the record */
- }
- if (0 != count)
- error("last record was incomplete. and had only %d bytes", count);
-
- I watch this one carefully because we bit a set of users once when
- we changed the round up/down choice in our library.
-